<?php
/* 接收json数据 */
require("../../utils/resolve_json.php");
/* sql操作工具 */
require("../../utils/tools.php");


if (!isset($data["name"])) {
    $code = 3000;
    $msg = "创建贴吧失败,贴吧名称不能为空!";
} else {
    if (!isset($data["category"])) {
        $code = 3001;
        $msg = "创建贴吧失败,贴吧分类不能为空!";
    } else {

        if (SQLTools::existTB($conn, 'tb', "tb_name='${data["name"]}'")) {
            $code = 3003;
            $msg = "创建贴吧失败,该贴吧名已存在!";
        } else {
            if (!SQLTools::existTB($conn, 'categories', "cg_uuid='${data["category"]}'")) {
                $code = 3004;
                $msg = "创建贴吧失败,该分类不存在!";
            } else {
                $uuid = SQLTools::$SQL_UUID;
                if (SQLTools::insertTB($conn, 'tb', 'tb_uuid,tb_name,tb_category,tb_create_time', "$uuid,'${data["name"]}','${data["category"]}',CURRENT_TIMESTAMP")) {
                    $code = 2000;
                    $msg = "创建贴吧成功!";
                } else {
                    $code = 3033;
                    $msg = "创建贴吧失败,原因未知!";
                }
            }
        }
    }
}
$result = array("code" => $code, "msg" => $msg);
echo json_encode_mz_urlencode($result);
